<template>
	<view class="container">
		<u-navbar placeholder title="开通快付通" :autoBack="true"></u-navbar>
		<view class="pad-32">
			<u--form labelPosition="left" :model="info" ref="form1" labelWidth="180rpx"
				:labelStyle="{fontSize: '28rpx'}">
				<view class="bg-white pad-left-right-24 pad-top-bottom-16 radius24">

					<u-form-item label="开户银行" prop="tel" :borderBottom="true">
						<view class="flex-w" @click="hanldeType(2)">{{cardText}}</view>
					</u-form-item>


					<u-form-item label="所在城市" prop="tel" :borderBottom="true">
						<u--input type="text" clearable placeholderClass="input-style" placeholder="请输入开户行所在城市"
							v-model="address" border="none"></u--input>
					</u-form-item>


					<u-form-item label="开户行名称" prop="tel" :borderBottom="true">
						<view class="flex-w" @click="hanldeType(1)">{{wifiText}}</view>
					</u-form-item>

					<u-form-item label="开户行联行号" prop="tel" :borderBottom="true">
						<u--input disabled type="text" clearable placeholderClass="input-style" placeholder="请选择开户行名称"
							v-model="info.merchantBankBranchNo" border="none"></u--input>
					</u-form-item>


					<u-form-item label="卡号" prop="tel" :borderBottom="true">
						<u--input type="text" clearable placeholderClass="input-style" placeholder="请输入账户卡号"
							v-model="info.settleBankAccount.settleBankAccountNo" border="none"></u--input>
					</u-form-item>

					<u-form-item label="开户姓名" prop="tel" :borderBottom="true">
						<u--input type="text" clearable placeholderClass="input-style" placeholder="请输入账户开户名"
							v-model="info.settleBankAccount.settleName" border="none"></u--input>
					</u-form-item>

					<u-form-item label="银行卡类型" prop="tel" :borderBottom="false">
						<u-radio-group v-model="info.settleBankAccount.settleAccountCreditOrDebit" placement="column"
							@change="groupChange">
							<view class="centerY">
								<u-radio :customStyle="{marginRight: '8px'}" v-for="(item, index) in radiolist"
									:key="index" :label="item.name" :name="item.value">
								</u-radio>
							</view>
						</u-radio-group>
					</u-form-item>
				</view>
			</u--form>

			<u-button :customStyle="{borderRadius: '12rpx'}" class="mar-top-96 font-32 button bg-theme"
				@click="submit">保存</u-button>

			<u-popup :show="selectShow" mode="bottom" round="10" closeable @close="hanldeClose">
				<view class="pad-30">
					<view class="text-center mar-bottom-30 font-30">请选择</view>
					<u-search placeholder="关键字搜索" @clear="hanldeClear" @custom="hanldeSearch"
						v-model="keyword"></u-search>
					<view class="list-box">
						<view @click="hanldeSelectId(item.code,item.title)" v-for="item in selectList"
							class="centerY betweenX border-bottom">
							<view class="text-center font-30 pad-20">{{item.title}}</view>
							<template v-if="type == 1">
								<u-icon v-if="addresCode.indexOf(item.code) > -1" name="checkbox-mark"
									color="#fc1003"></u-icon>
							</template>
							<template v-if="type == 2">
								<u-icon v-if="settleBankNoCode.indexOf(item.code) > -1" name="checkbox-mark"
									color="#fc1003"></u-icon>
							</template>
						</view>
					</view>
					<u-button :customStyle="{borderRadius: '12rpx'}" class="mar-top-30 font-32 button bg-theme"
						@click="hanldeConfirm">确定选择</u-button>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import {
		bindKftCard,
		dictGetAll
	} from '@/config/api.js'
	export default {
		data() {
			return {
				// 所在城市
				address: '',
				radiolist: [{
					name: '借记卡',
					value: '1',
				}, {
					name: '贷记',
					value: '2',
				}],
				// 选择弹窗
				selectShow: false,
				wifiText: '请选择开户行名称',
				cardText: '请选择你的银行卡',
				// 开户数据
				info: {
					merchantBankBranchNo: '',
					merchantBankBranchName: '',
					settleBankAccount: {
						settleBankNo: '',
						settleBankAccountNo: '',
						settleName: '',
						settleBankAcctType: '1',
						settleAccountCreditOrDebit: '1',
					}
				},
				// 获取卡
				cardList: [],
				// 地址数据
				addressList: [],
				// 关键字搜索
				keyword: '',
				// 枚举字段数据
				selectList: [],
				// 判断选择的枚举
				type: 1,
				// 银行卡
				settleBankNoCode: '',
				addresCode: ''
			}
		},
		onLoad() {
			// 获取一些枚举
			this.getAllList(1);
		},
		methods: {
			// 获取枚举
			getAllList(type, title = '') {
				dictGetAll({
					gid_arr: [type],
					s_title: title
				}).then(res => {
					this.selectList = res.data.lists[type];
					this.operateList = JSON.parse(JSON.stringify(res.data.lists[type]));
				})
			},
			// 关闭弹窗
			hanldeClose() {
				this.selectShow = false;
			},
			// 切换数据
			hanldeType(e) {
				this.type = e;
				this.keyword = '';
				if (e == 1) {
					if (this.cardText == '请选择你的银行卡') {
						uni.$u.toast(this.cardText);
						return
					}
					// 请输入所在在城市
					if (this.address == '') {
						uni.$u.toast('请输入开户行所在在城市');
						return
					}
					let text = `${this.cardText}%${this.address}`;
					this.getAllList(3, text);
				} else {
					this.getAllList(1);
				}
				this.selectShow = true;
			},
			// 选择银行卡类型
			groupChange(e) {
				console.log(e)
			},
			// 取消
			hanldeClose() {
				this.selectShow = false;
			},
			// 确定
			hanldeConfirm(e) {
				this.selectShow = false;
			},
			// 提交开通数据
			submit() {
				if (this.cardText == '请选择你的银行卡') {
					uni.$u.toast(this.cardText);
					return
				}

				// 请输入所在在城市
				if (this.address == '') {
					uni.$u.toast('请输入开户行所在在城市');
					return
				}

				bindKftCard(this.info).then(res => {
					uni.$u.toast(res.msg);
					setTimeout(() => {
						uni.navigateBack();
					}, 1000)
				})
			},
			// 点击搜索
			hanldeSearch(e) {
				this.selectList = [];
				this.operateList.forEach(item => {
					if (item.title.indexOf(e) != -1) {
						this.selectList.push(item);
					}
				})
			},
			// 清空
			hanldeClear() {
				this.selectList = this.operateList;
			},
			// 选择想要的数据
			hanldeSelectId(code, text) {
				if (this.type == 1) {
					this.addresCode = code;
					this.wifiText = text;
					this.info.merchantBankBranchName = text;
					this.info.merchantBankBranchNo = code;
				} else {
					this.settleBankNoCode = code;
					this.cardText = text;
					this.info.settleBankAccount.settleBankNo = code;
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .u-navbar__content {
		background-image: url('../../static/image/my-bg.png');
		background-size: cover;
		background-repeat: no-repeat;
		background-color: #f5f5f5;
	}


	.button {
		box-shadow: 0 10px 15px rgba(223, 0, 7, .1);
		height: 96rpx;
		color: white;
	}

	/deep/ .u-form-item__body {
		height: 100rpx;
	}

	.list-box {
		height: 50vh;
		overflow-y: scroll;
	}

	.input-style {
		color: rgb(192, 196, 204) !important;
		background: white;
	}

	.container {
		padding-top: var(--status-bar-height); //给组件加个上边距
		box-sizing: border-box;
		background: url('../../static/image/my-bg.png') no-repeat;
		background-size: 100% 100%;
		height: 100vh;
	}

	.border-bottom {
		border-bottom: 1px solid rgb(214, 215, 217);
	}

	::v-deep .uni-input-input:disabled {
		background: white;
	}
</style>